package com.yanqu.road.server.cmd.relatives;

import com.yanqu.road.pb.relatives.RelativesProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.relatives.RelativesModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_RELATIVES_CANCEL, desc = "解除亲家")
public class RelativesCancelCmd extends AbstractCommand {

	private long relativesId;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		RelativesProto.CancelRelativesReqMsg reqMsg = RelativesProto.CancelRelativesReqMsg.parseFrom(packet.getBytes());
		relativesId = reqMsg.getRelativesId();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		ret = player.getModule(RelativesModule.class).cancelRelatives(relativesId);
	}

	@Override
	public void sendData(GamePlayer player) {
		if(ret != -1) {
			RelativesProto.CancelRelativesRespMsg.Builder respMsg = RelativesProto.CancelRelativesRespMsg.newBuilder();
			respMsg.setRet(ret);
			player.sendPacket(Protocol.U_RELATIVES_CANCEL, respMsg);
		}
	}

}
